<%@ page import="java.util.*,blog.entities.*" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>JSTL</title>
<style type="text/css">
	.red {
		background-color: red;
	}
</style>
</head>
<body>

	<%
		request.setAttribute("name", "孙悟空");
		User user = new User();
		user.setId(1001);
		user.setUsername("swk");
		request.setAttribute("user", user);
		
		User user2 = new User();
		user2.setUsername("swk2");
		user2.setId(1002);
		request.setAttribute("user2", user2);
		
		//Map
		Map<String,User> map = new HashMap<>();
		map.put(user.getId() + "",user);
		map.put(user2.getId() + "",user2);
		request.setAttribute("uMap", map);
		
		// 数组
		User[] users = new User[2];
		users[0] = user;
		users[1] = user2;
		session.setAttribute("users", users);
		
		// 
		List<User> userList = new ArrayList<>();
		userList.add(user);
		userList.add(user2);
		request.setAttribute("userList", userList);
		
		request.setAttribute("time", new Date());
	%>

	<c:if test="${param.age gt 18 }" scope="session" var="flag" >
		成年人
		${flag }
	</c:if>
	
	<c:choose>
		<c:when test="${param.age gt 60 }">
			<br>老当益壮
		</c:when>
		<c:when test="${param.age gt 40 }">
			<br>中年人
		</c:when>
		<c:otherwise>
			<br>年轻人<br>
		</c:otherwise>
	</c:choose>
	
	<hr>
	
	<c:if test="${not empty userList }">
		<!-- 如果不为null，我们去遍历 -->
		<table>
			<tr>
				<td>id</td>
				<td>id</td>
			</tr>
		<c:forEach items="${userList }" var="user" varStatus="vs">
			<tr class="${vs.count %2 == 0 ? '':'red' }">
				<td>${user.id } - ${vs.index }</td>
				<td>${user.username } - ${vs.index }</td>
			</tr>
			</table>
		</c:forEach>

	</c:if>
	
	<c:if test="${empty userList }">
		<p>当前没有数据</p>
	</c:if>

	<h3>fmt</h3>
	<fmt:formatDate value="${time}" pattern="yyyy-MM-dd"/>
	
	<c:set var="ctx" value="${pageContext.request.contextPath }">
	</c:set>
	${ctx}
	<br>
	<c:out value="${ctx}"></c:out>
	
	
	<h3>url</h3>
	<c:url var="myhref" value="/b.jsp"></c:url>
	${myhref}
	
	<h3>url</h3>
<%-- 	<c:redirect url="a.jsp"></c:redirect> --%>
	
	<h3>forTokes</h3>
	<c:if test="${not empty userList }">
		<table>
			<tr>
				<td>Id</td>
				<td>Username</td>
			</tr>
			<c:forTokens items="QQ,QQ2,QQ3" delims="," var="user">
				<tr>
					<td>${user}</td>
				</tr>
			</c:forTokens>
		</table>
		
	</c:if>

</body>
</html>